var vue = new Vue({
    el: '#app',
    data: function () {
        return {
            visible: false,
            activeNames:'1' ,
            account: '',
            username:'',
            tableData: [],
            currentPage4:1,
            dialogForm:false,
            checkForm:false,
            selectForm:false,
            updateForm:false,
            formData:{},
            updateData:{
                id:'',
                account:'',
                username:'',
                gender:'',
                phone:'',
                status:''
            },
            checkData:[],

        }
    },
    //钩子函数，VUE对象初始化完成自动执行
    created() {
        this.getAll();
    },
    methods: {
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
        },
        handleChange(val) {
            console.log(val);
        },
        getAll() {
            //发送异步请求
            var self = this;
            Util.post("/sysUser/listUser", {}, function (result){
                self.tableData=result.data;
            });
        },
        //弹出添加窗口
        create(){
            this.dialogForm=true;
            this.rest();
        },
        //弹出编辑窗口
        createUpdate(row){
            this.updateForm=true;
            console.log(row);
            this.updateData=row;
        },
        //弹出模糊查询窗口
        select(){
            var sysUser={
                "account": this.account,
                "username": this.username
            }
            var self = this;
            Util.postJson("/sysUser/selectByUser",sysUser,function(result){
                self.tableData=result.data;
            });
        },
        //重置新增表单
        rest(){
            this.formData={};
        },
        //取消按钮
        cancel(){
            this.dialogForm=false;
            this.updateForm=false;
        },
        //开始添加
        handleAdd(){
            var self = this;
            Util.postJson("/sysUser/addUser",self.formData,function (result){
                //关闭
                self.dialogForm=false;
                if (result.success){
                    self.$message.success("添加成功");
                }else {
                    self.$message.error("添加失败，账号已存在");
                }

                //重新加载
                self.getAll();

            });
        },
        //开始编辑
        handleUpdate(){
            var self = this;
            Util.postJson("/sysUser/updateUser",self.updateData,function (result){
                //关闭
                self.updateForm=false;
                //重新加载
                self.getAll();
            });
        },
        //删除
        handleDelete(row){
            // console.log(row);
            var self = this;
            Util.post("/sysUser/deleteUser/"+row.id,{},function (result){
                console.log(result)
                if (result.success){
                    self.$message.success("删除成功");
                }else{
                    self.$message.error("删除失败");
                }
                self.getAll();
            });
        },
        //查询单个数据
        check(row){
            var self = this;
            self.checkForm=true;
            self.checkData.account=row.account;
            self.checkData.username=row.username;
            self.checkData.password=row.password;
            self.checkData.gender=row.gender;
            self.checkData.phone=row.phone;
            self.checkData.status=row.status;
            self.checkData.createTime=row.createTime;
            self.checkData.createUserId=row.createUserId;
            self.checkData.editTime=row.editTime;
            self.checkData.editUserId=row.editUserId;
            self.checkData.deleteFlag=row.deleteFlag;
        },
    }
})